package main

import (
	plugins "argus_go_server/plugins"
	routes "argus_go_server/router"
	"net/http"
	"os"
	"path/filepath"

	"github.com/gin-gonic/gin"
	"github.com/go-ini/ini"
)

var (
	cfg  *ini.File
	port string
	host string
)

func getServerConfig() {
	port = cfg.Section("server").Key("PORT").String()
	host = cfg.Section("server").Key("HOST").String()
}

// 初始化项目
func init() {
	// 获取当前路径
	wd, _ := os.Getwd()
	configPath := filepath.Join(wd, "conf", "app.ini")

	var err error
	cfg, err = ini.Load(configPath)
	if err != nil {
		panic(err)
	}
	getServerConfig()

}
func main() {
	r := gin.Default()
	// 配置静态服务器
	r.Static("/static", "./static")

	// 加载redis服务
	plugins.RedisServer{}.InitRedis()

	// 加载websocket服务
	plugins.WersbocketServer{}.InitWersbocket("8888")

	// 加载用户路由
	routes.UserRouteInit(r)
	r.GET("/ping", func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{
			"message": "pong",
		})
	})
	gin.SetMode(gin.DebugMode)
	r.Run(host + ":" + port)
}
